$(function(){
    $('#taskCode').focus();
    taskDataFormValid();
    //保存验证
    $("#subBtn").on('click',function () {
        submitForm();
    })
})
function taskDataFormValid() {
    $("#taskDataForm").validate({
        rules: {
            b_iotCode: {
                required: true,
                minlength: 3,
                isCode: true,
            },
            b_iotName: {
                required: true,
                minlength: 3,
            },
            b_iotTable:{
                required: true,
                minlength: 6,
            },
            b_iotScale:{
                range:[0,5]
            },
            b_rowSort:{
                isDigits: true
            }
        },
        errorPlacement: function(error, element) {
            error.appendTo(element.parent());
        },
        errorElement: "span",
        errorClass: "errorDevice",
        success: 'valid',
        messages: {
            b_iotCode: {
                required: " (必填)",
                minlength: " (不能少于 3 个字母)",
            },
            b_iotName: {
                required: " (必填)",
                minlength: " (不能少于 3 个字母)",
            },
            b_iotTable:{
                required: " (必填)",
                minlength: " (不能3 个字母)"
            },
            b_iotScale:{
                range:"输入0-5数字"
            },
            b_rowSort: {
                required: true,
                minlength: 1,
                isPositiveInteger: true
            }
        },
    });
}

function submitForm() {
    if($('#taskDataForm').valid()){
        return false;
    }
    return {};
}
jQuery.validator.addMethod("isCode", function(value, element) {
    return this.optional(element) || /^[A-Z]{3}[0-9]{4}$/.test(value);
},'请输入3位大写字母＋4位数字');
